/*
 * CastDRAndroid
 * Copyright (c) 2014 Christian Holm Christensen
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 *
 */
package org.cholm.media.castdr.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.cholm.media.castdr.R;
import org.cholm.media.castdr.adapters.TopAdapter;

import org.cholm.media.castdr.LogUtils; import static org.cholm.media.castdr.LogUtils.LOGd;
/**
 * @author cholm
 *         <p/>
 *         The top-view fragment. This is a pager of with a fragment of each of
 *         the categories
 */
public class TopFragment extends Fragment {
    private static final String TAG = LogUtils.makeLogTag(TopFragment.class);
    /**
     * Our pager
     */
    private ViewPager mPager = null;
    /**
     * The pager adapter
     */
    private TopAdapter mAdapter = null;

    /**
     * Create our view
     */
    public View onCreateView(LayoutInflater inflator, ViewGroup container,
                             Bundle savedInstance) {
        setRetainInstance(true);
        mPager =
                (ViewPager) (inflator.inflate(R.layout.category_pager,
                        container,
                        false));
        mAdapter = new TopAdapter(getActivity().getSupportFragmentManager());
        mPager.setAdapter(mAdapter);
        mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                // When swiping between pages, select the
                // corresponding tab.
                // allowLoad(position);
                // getActionBar().setSelectedNavigationItem(position);
                LOGd(TAG, "Selected page "
                        + mAdapter.getCategory(position).getName());
            }
        });
        LOGd(TAG, "Created top fragment");

        return mPager;
    }

    public ViewPager getPager() {
        return mPager;
    }
}
// EOF
